﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace _2011DBProject
{
    public partial class MakeRoom : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void btnGoLogout_onclick(object sender, EventArgs e)
        {
            Session.Clear();
            Response.Redirect("Default.aspx");
        }
        protected void btnGoServer_onclick(object sender, EventArgs e)
        {
            Response.Redirect("Server.aspx");
        }
        protected void btnGoCharacter_onclick(object sender, EventArgs e)
        {
            Response.Redirect("Character.aspx");
        }
        protected void btnGoChannel_onclick(object sender, EventArgs e)
        {
            Response.Redirect("Channel.aspx");
        }
        protected void btnGoGameroom_onclick(object sender, EventArgs e)
        {
            Response.Redirect("Gameroom.aspx");
        }

        protected void chkPassword_onclick(object sender, EventArgs e)
        {
            //if(CheckBox1.Checked)

        }


        protected void btnMakeRoom_Click(object sender, EventArgs e)
        {
            try
            {
                DataSet1 ds = new DataSet1();
                DataSet1TableAdapters.GAMEROOMTableAdapter taGameroom = new DataSet1TableAdapters.GAMEROOMTableAdapter();
                taGameroom.Connection.ConnectionString = Settings.strConnectionString;

                DataSet1.GAMEROOMRow r = ds.GAMEROOM.NewGAMEROOMRow();
                r.CHANNEL_NO = Convert.ToDecimal(Session["Ch"]);
                r.SERVER_NO = Convert.ToDecimal(Session["SERVER"]);
                r.GAME_TYPE = DropDownRule.SelectedValue;
                r.GAMEROOM_NAME = txtRoomName.Text;
                r.HOLE_QTY = Convert.ToDecimal(DropDownHoles.SelectedValue);
                r.PARTICIPANT_QTY = Convert.ToDecimal(DropDownPeople.SelectedValue);
                r.MIN_LEVEL = Convert.ToDecimal(DropDownMinLv.SelectedValue);
                r.COURSE_NO = Convert.ToDecimal(DropDownCource.SelectedValue);

                if (CheckBox1.Checked == true)
                    r.PASSWORD = txtPass.Text;
                else
                    r.PASSWORD = "";

                bool isFull = true;
                int i;
                for (i = 1; i < 100; i++)
                {
                    if (taGameroom.ScalarQueryFindRoomNO(Convert.ToDecimal(Session["SERVER"]), Convert.ToDecimal(Session["Ch"]), i) == 0)
                    {
                        r.GAMEROOM_NO = i;
                        isFull = false;
                        break;
                    }
                }

                if (isFull)
                {
                    string script = "<script>alert('에러번호 - #05 : 관리자에게 문의하세요.');</script>";
                    Page.ClientScript.RegisterClientScriptBlock(typeof(string), "confirm", script);
                }
                else
                {
                    ds.GAMEROOM.AddGAMEROOMRow(r);
                    taGameroom.Update(ds.GAMEROOM);
                    Session.Add("GAMEROOM", i);
                }
                sqldsGameroom.DataBind();
                GridView1.DataBind();
            }
            catch
            {
                string script = "<script>alert('에러번호 - #04 : 관리자에게 문의하세요.');</script>";
                Page.ClientScript.RegisterClientScriptBlock(typeof(string), "confirm", script);
            }
        }
    }

}
